/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package UserGroup;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Mukesh
 */
public class UserGroupList extends HttpServlet {
   
  
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            
            Vector<UserGroupBean> list=new Vector<UserGroupBean>();
            list=UserGroup.Query.viewAll();
            if(!list.isEmpty())
           {
               Iterator it=list.iterator();
               while(it.hasNext())
               {
                  UserGroupBean ugb=(UserGroupBean)it.next();
                  out.println("<tr id='"+ugb.getGroup_id()+"'>");
                  out.println("<td><center>");
                  out.println(ugb.getGroupName());
                  out.println("</center></td>");
                  out.println("<td><center>");
                  out.println(ugb.getUserType());
                  out.println("</center></td>");
                  out.println("<td><center>");
                  out.println("<a href='EditUserGroup.jsp?id="+ugb.getGroup_id()+"&gname="+ugb.getGroupName()+"&userType="+ugb.getUserType()+"'><button class='btn btn-info'>Edit</button></a>");
                  out.println("<a href='#'><button class='btn btn-danger' onclick='deleteGroupConfirm("+ugb.getGroup_id()+")'>Delete</button></a>");
                  out.println("</center></td>");
                  out.println("</tr>");
               }
           }
           else
           {
               out.println("<tr>");
               out.println("<td colspan='3'>");
               out.println("<b>No Record Found</b>");
               out.println("</td>");
               out.println("</tr>");}
            }catch(Exception e){
            
            } finally {
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
